<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="数学建模算法5-层次分析法, python,machine learning,deep learning,html,css,c,c++,cpp,cmake,ros,linux,ubuntu">
    <meta name="description" content="本文主要介绍了数学建模中常见的评价方法：层次分析法">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>数学建模算法5-层次分析法 | JackWang&#39;s Blog</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 5.4.2">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"></head>



   <style>
    body{
       background-image: url(https://cdn.jsdelivr.net/gh/Tokisaki-Galaxy/res/site/medias/background.jpg);
       background-repeat:no-repeat;
       background-size: 100% 100%;
       background-attachment:fixed;
    }
</style>



<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">JackWang&#39;s Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-book-reader" style="zoom: 0.6;"></i>
      
      <span>博客</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/tags">
          
          <i class="fas fa-tags" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按标签归类文章</span>
        </a>
      </li>
      
      <li>
        <a href="/categories">
          
          <i class="fas fa-bookmark" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按目录归类文章</span>
        </a>
      </li>
      
      <li>
        <a href="/archives">
          
          <i class="fas fa-archive" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按日期分类文章</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>



<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">JackWang&#39;s Blog</div>
        <div class="logo-desc">
            
            JackWang的个人博客
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-book-reader"></i>
			
			博客
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a href="/tags " style="margin-left:75px">
				  
				   <i class="fa fas fa-tags" style="position: absolute;left:50px" ></i>
			      
                              <span>按标签归类文章</    span>

                  </a>
                </li>
              
                <li>

                  <a href="/categories " style="margin-left:75px">
				  
				   <i class="fa fas fa-bookmark" style="position: absolute;left:50px" ></i>
			      
                              <span>按目录归类文章</    span>

                  </a>
                </li>
              
                <li>

                  <a href="/archives " style="margin-left:75px">
				  
				   <i class="fa fas fa-archive" style="position: absolute;left:50px" ></i>
			      
                              <span>按日期分类文章</    span>

                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('抱歉，这篇文章并不想让所有人都看到，请输入授权密码观看')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/v2-986c79a5dfbf54baa7dbe8c29d5f6734_1440w.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">数学建模算法5-层次分析法</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Python/">
                                <span class="chip bg-color">Python</span>
                            </a>
                        
                            <a href="/tags/Math-Modeling/">
                                <span class="chip bg-color">Math Modeling</span>
                            </a>
                        
                            <a href="/tags/%E5%B1%82%E6%AC%A1%E5%88%86%E6%9E%90%E6%B3%95/">
                                <span class="chip bg-color">层次分析法</span>
                            </a>
                        
                            <a href="/tags/Analytic-Hierarchy-Process/">
                                <span class="chip bg-color">Analytic Hierarchy Process</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AE%97%E6%B3%95/" class="post-category">
                                数学建模算法
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-01-04
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2023-06-01
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    7k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    25 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <blockquote>
<p>本文主要介绍了数学建模中常见的评价方法：层次分析法</p>
</blockquote>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/v2-986c79a5dfbf54baa7dbe8c29d5f6734_1440w.jpg" alt="层次分析法"></p>
<h1 id="数学建模算法5-层次分析法"><a href="#数学建模算法5-层次分析法" class="headerlink" title="数学建模算法5-层次分析法"></a>数学建模算法5-层次分析法</h1><p>层次分析法是数学建模中非常常用的算法之一，通过层次分析法，我们能够完成对一个复杂的问题的定性与定量分析，并且在分析的同时做出决策。</p>
<h2 id="1-层次分析法介绍"><a href="#1-层次分析法介绍" class="headerlink" title="1. 层次分析法介绍"></a>1. 层次分析法介绍</h2><p><strong>层次分析法（Analytic Hierarchy Process，AHP）</strong>是美国运筹学家匹茨堡大学教授萨蒂（T.L.Santy）于上世纪70年代初，为美国国防部研究《根据各个工业部门对国家福利的贡献大小而进行电力分配》课题时，应用网络系统理论和多目标综合评价方法，提出的一种层次权重决策分析方法。</p>
<p>这种方法的特点是在对复杂的决策问题的本质、影响因素及其内在关系等进行深入分析的基础上，<strong>利用较少的定量信息使决策的思维过程数学化</strong>，从而为多目标、多准则或无结构特性的复杂决策问题提供简便的决策方法。是对难于完全定量的复杂系统作出决策的模型和方法。</p>
<p>简单的说，其优点在于：</p>
<ul>
<li>可以使用少量的信息（数据）来指导进行决策，相比于以往的其他模型，他们都是完全的定量化的，因此需要大量的数据。</li>
<li>层次分析法非常善于对不易于定量的问题进行分析。</li>
</ul>
<p>人们在对社会、经济以及管理领域的问题进行系统分析时，面临 的经常是一个由相互关联、相互制约的众多因素构成的复杂系统。 层次分析法则为研究这类复杂的系统，提供了一种新的、简洁的、 实用的决策方法。</p>
<p>层次分析法是一种解决多目标的复杂问题的定性与定量相结合的决策分析方法。</p>
<p><strong>该方法将定量分析与定性分析结合起来， 用决策者的经验判断各衡量目标能否实现的标准之间的相对重要程度，并合理地给出每个决策方案的每个标准的权数，利用权数求出各方案的优劣次序，从而比较有效地应用于那些难以用定量方法解决的课题。</strong></p>
<p>层次分析法是社会、经济系统决策中的有效工具。其特征是合理地将定性与定量的决策结合起来，按照思维、心理的规律把<strong>决策过程层次化、数量化</strong>。是系统科学中常用的一种系统分析 方法。</p>
<p>该方法自1982年被介绍到我国以来，以其定性与定量相结合地 处理各种决策因素的特点，以及其系统灵活简洁的优点，迅速地在我国社会经济各个领域内，如工程计划、资源分配、方案 排序、政策制定、冲突问题、性能评价、能源系统分析、城市 规划、经济管理、科研评价等，得到了广泛的重视和应用。</p>
<p>层次分析法的三大运用：</p>
<ul>
<li>用于最佳方案的选取（选择运动员、选择地址）<ul>
<li>例如四个远动员A、B、C、D，我们分别从耐力、爆发、敏捷几个因素去评价运动员的好坏</li>
<li>例如医院选址，那么对多个不同的地点，可以从低价、人口密度等因素评价医院选址的好坏</li>
</ul>
</li>
<li>用于评价类问题（评价水质状况、评价环境）<ul>
<li>同上</li>
</ul>
</li>
<li>用于指标体系的优选（兼顾科学和效率）<ul>
<li>例如现在有9个指标，要从中选取出来6个指标，那么对指标剔除评价标准，例如科学性和效率性</li>
</ul>
</li>
</ul>
<h2 id="2-层次分析法的基本原理"><a href="#2-层次分析法的基本原理" class="headerlink" title="2. 层次分析法的基本原理"></a>2. 层次分析法的基本原理</h2><h3 id="A-决策"><a href="#A-决策" class="headerlink" title="A. 决策"></a>A. 决策</h3><p>决策是指在面临多种方案时需要<strong>依据一定的标准选择某一种方案</strong>。 日常生活中有许多决策问题。例如：</p>
<ul>
<li>在海尔、新飞、容声和雪花四个牌号的电冰箱中选购一 种。要考虑品牌的信誉、冰箱的功能、价格和耗电量。</li>
<li>在泰山、杭州和承德三处选择一个旅游点。要考虑景点 的景色、居住的环境、饮食的特色、交通便利和旅游的费用。</li>
<li>在基础研究、应用研究和数学教育中选择一个领域申报 科研课题。要考虑成果的贡献（实用价值、科学意义），可行性 （难度、周期和经费）和人才培养</li>
<li>在小丽、小美、小静中选择一个适合自己的女朋友。要 考虑基本颜值，身材比例、教育程度、家境情况、地域关系等</li>
</ul>
<h3 id="B-基本原理"><a href="#B-基本原理" class="headerlink" title="B. 基本原理"></a>B. 基本原理</h3><p>层次分析法根据问题的性质和要达到的总目标，将<strong>问题分解为不同的组成因素</strong>，并<strong>按照因素间的相互关联影响以及隶属关系将因素按不同层次聚集组合，形成一个多层次的分析结构模型</strong>，从而最终<strong>使问题归结为最低层(供决策的方案、措施等)相对于最高层(总目标)的相对重要权值的确定或相对优劣次序的排序</strong>。</p>
<h2 id="3-层析分析法的步骤和方法"><a href="#3-层析分析法的步骤和方法" class="headerlink" title="3. 层析分析法的步骤和方法"></a>3. 层析分析法的步骤和方法</h2><p> 运用层次分析法构造系统模型时，大体可以分为以下四个步骤：</p>
<ol>
<li>建立层次结构模型</li>
<li>构造判断(成对比较)矩阵</li>
<li>层次单排序及其一致性检验</li>
<li>层次总排序及其一致性检验</li>
</ol>
<h3 id="A-建立层次结构模型"><a href="#A-建立层次结构模型" class="headerlink" title="A. 建立层次结构模型"></a>A. 建立层次结构模型</h3><p>在这一层，我们将决策的目标、考虑的因素（决策准则）和决策对象按它们之间的相互关系分为最高层、中间层和最低层，绘出层次 结构图。一般来说，三层分别是：</p>
<ul>
<li><strong>最高层</strong>：决策的目的、要解决的问题。比如去旅游</li>
<li><strong>最低层</strong>：决策时的备选方案。比如去桂林还是去西安还是去浙江</li>
<li><strong>中间层</strong>：考虑的因素、决策的准则。预算、想去的景区等等</li>
</ul>
<p>此外，<strong>对于相邻的两层，称高层为目标层，低层为因素层</strong>。</p>
<p>举例来说，</p>
<ul>
<li><p><strong>大学毕业生就业选择问题</strong>：获得大学毕业学位的毕业生，在“双向选择”时，用人单位与毕业生都有各自的选择标准和要求。就毕业生来说选择单位的标准和要求是多方面的，例如：</p>
<ul>
<li>能发挥自己才干作出较好贡献（即工作岗位适合发挥自己的专长）</li>
<li>工作收入较好（待遇好）</li>
<li>生活环境好（大城市、气候等工作条件等）</li>
<li>单位名声好（声誉等）</li>
<li>工作环境好（人际关系和谐等）</li>
<li>发展晋升机会多（如新单位或前景好）等</li>
</ul>
<p>那么根据上面的指标，绘制得到的层次结构图为：</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220104233008393.png" alt="大学生毕业就业选择问题"></p>
</li>
<li><p><strong>选择旅游目的地</strong>：在3个目的地中按照景色、费用、居住条件等因素选择最终前往的城市</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220104233208220.png" alt="旅游目的地选择问题"></p>
</li>
</ul>
<p>因此，第一步建立层次结构模型的整个思维过程的归纳如下：</p>
<ul>
<li>将决策问题分为3个或多个层次</li>
<li><strong>最高层</strong>：<strong>目标层</strong>，表示解决问题的目的，即层次分析要达到的总目标。通常只有一个总目标。</li>
<li><strong>中间层</strong>：<strong>准则层、指标层、……</strong>。表示采取某种措施、政策、方案等为了实现预定总目标所涉及的中间环节；根据指标的不同，可以是准则层、指标层、 策略层、约束层等。</li>
<li><p><strong>最低层</strong>：<strong>方案层</strong>。表示将选用的解决问题的各种措施、政策、方 案等。通常有几个方案可选。</p>
</li>
<li><p>每层有若干元素，层间元素的关系用相连直线表示。</p>
</li>
<li>层次分析法所要解决的问题是关于最低层对最高层的相对权重问题，按此相对权重可以对最低层中的各种方案、措施进行排序，从 而在不同的方案中作出选择或形成选择方案的原则。即我们首先给目标层和准则层之间有一个权重向量，然后方案层中的每一个方案都有一个准则层对应的得分向量。两个向量相乘得到得分，那么我们就可以根据得分进行排序，获得初步的方案</li>
</ul>
<h3 id="B-构造判断-成对比较-矩阵"><a href="#B-构造判断-成对比较-矩阵" class="headerlink" title="B. 构造判断(成对比较)矩阵"></a>B. 构造判断(成对比较)矩阵</h3><p>在确定各层次各因素之间的权重时，如果只是定性的结果，则 常常不容易被别人接受，因而Santy等人提出：一致矩阵法，即:</p>
<ol>
<li>不把所有因素放在一起比较，而是两两相互比较。即所有中间层的准则/因素间进行两两比较</li>
<li>对此时采用相对尺度，以尽可能减少性质不同的诸因素相互比较的困难，以提高准确度。即使用谁更重要，谁更不重要这样的判断，而非谁比谁好多少，谁比谁好几倍。例如身高的比较，用高一点，高很多这种，而非高1.7厘米</li>
</ol>
<p>判断矩阵是表示本层所有因素针对上一层某一个因素的相对重要性的比较。判断矩阵的元素$a_{ij}$用Santy的1—9标度方法给出。</p>
<p>注意，心理学家认为成对比较的因素不宜超过9个，即每层不要超过9个因素。</p>
<p>而具体的1-9的标度的具体的含义如下：</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220104234600062.png" alt="1-9标度的含义"></p>
<p>此外，指标1对于指标2的标度为5，那么指标2对指标1的标度为$\frac 1 5$。</p>
<p>例如对于旅游目的地选取问题，我们根据前一步的得到的准则层，对其中的准则之间进行两两比较，得到下面的判断矩阵</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220104234906589.png" alt="判断矩阵"></p>
<p>但其实此时得到的判断矩阵是有问题，例如有$\frac {C_1}{C_2}=\frac 1 2$，而$\frac{C_2}{C_3}=7$，那么$\frac{C_1}{C_3}=\frac 7 2$，但是上述我们给出的$\frac {C_1}{C_3}$却是4，因此是存在不一致问题。</p>
<p>因此，在判断矩阵中，<strong>允许不一致，但要确定不一致的允许范围</strong></p>
<p>若矩阵中任意三个相关联的数字是一致的，即$a<em>{ik}\cdot a</em>{kj}=a_{ij}$，那么此时<strong>称对比矩阵为一致阵，反之为不一致阵</strong>。</p>
<p>一致阵的性质有：</p>
<ul>
<li>A的秩为1，A的唯一非零特征根为n，即矩阵的行/列数。（$A\vec w=n\vec w$）</li>
<li>非零特征根n所对应的特征向量归一化后可作为权向量</li>
</ul>
<p>而对于不一致(但在允许范围内)的成对比较阵A， Santy等人建议用对应于最大特征根的特征向量作为权向量</p>
<p>而允许范围的判断及界定则由第三步完成</p>
<h3 id="C-层次单排序以及其一致性检验"><a href="#C-层次单排序以及其一致性检验" class="headerlink" title="C. 层次单排序以及其一致性检验"></a>C. 层次单排序以及其一致性检验</h3><blockquote>
<p>注意，如果是一致阵的话，权重向量已经获得，而第三步都是针对不一致阵的。</p>
</blockquote>
<h4 id="1-层次单排序"><a href="#1-层次单排序" class="headerlink" title="1) 层次单排序"></a>1) 层次单排序</h4><p>所谓层次单排序，即指对特征根最大的特征向量中的分量进行归一化操作之后，让各元素的值的和为1的过程。而归一化之后的向量记为$W$。</p>
<p>因为$W$的元素为同一层次因素对于上一层次因素相对重要性的排序权值，这一过程称为层次单排序。</p>
<h4 id="2-一致性检验"><a href="#2-一致性检验" class="headerlink" title="2) 一致性检验"></a>2) 一致性检验</h4><p>然而我们在这里其实还并不知道我们的不一致阵的不一致程度是否在允许范围内，因此需要对这里层次单排序之后的权向量进行一致性检验。即衡量一个不一致阵的不一致性，然后根绝量化后的不一致性进行判断。衡量不一致性，其实可以用不一致阵和一致阵的偏差来进行描述，因此要借助下面的两个定理：</p>
<ol>
<li><strong>定理一：$n$阶一致阵的唯一非零特征根为$n$</strong></li>
<li><strong>定理二：$n$阶正互反阵$A$的最大特征根$\lambda\ge n$, 当且仅当$\lambda=n$时，A为一致阵</strong></li>
</ol>
<p>因此就可以通过衡量$\lambda$与$n$的关系来描述$A$的不一致性。即由于$\lambda$连续的依赖于$a_{ij}$，则$\lambda$比$n$ 越大，$A$的不一致性越严重。则此时用最大特征值对应的特征向量作为被比较因素对上层某因素影响程度的权向量，其不一致程度越大，引起的判断误差越大。 因而可以用$\lambda-n$数值的大小来衡量$A$的不一致程度。</p>
<p>因此，定义<strong>不一致性指标$CI$</strong>：</p>
<script type="math/tex; mode=display">
CI=\frac {\lambda-n} {n-1}</script><p>因此，有</p>
<ul>
<li>$CI$等于0，有完全的一致性</li>
<li>$CI$接近于0，有满意的一致性</li>
<li>$CI$越大，不一致越严重</li>
</ul>
<p>因此衡量一个不一致阵是否是可以接受的，关键就是看这个不一致阵的$CI$是否在某个范围内。因此关键就在于选取这个范围。又已知$CI=0$表示完全的一致性，因此其实只需要得到一个大于0的上界即可。</p>
<p>为了获得这个上界，那么可以通过和随机构造的随机矩阵的CI的值进行比较，来衡量我们给出的非一致判断阵和随机给出的判断阵之间的关系，从而衡量我们给出的判断阵是否合理，若合理即表示虽然不一致，但是在允许范围内。</p>
<p>因此，引入入<strong>随机一致性指标$RI$</strong>。$RI$的计算方法如下：</p>
<ul>
<li><p>随机构造500个的成对比较矩阵$A<em>1$，$A_2$，……，$A</em>{500}$</p>
</li>
<li><p>对每个大小的矩阵计算$CI$，得到$CI_i,i=1,\cdots,500$</p>
</li>
<li><p>得到$RI$，计算公式如下：</p>
<script type="math/tex; mode=display">
RI=\frac{CI_1+CI_2+\cdots+CI_500}{500}=\frac{\frac {\lambda_1+\lambda_2+\cdots+\lambda_500}{500}-n}{n-1}</script></li>
</ul>
<p>对不同大小的判断镇分别计算RI，得到下表</p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:center">N</th>
<th style="text-align:center">1</th>
<th style="text-align:center">2</th>
<th style="text-align:center">3</th>
<th style="text-align:center">4</th>
<th style="text-align:center">5</th>
<th style="text-align:center">6</th>
<th style="text-align:center">7</th>
<th style="text-align:center">8</th>
<th style="text-align:center">9</th>
<th style="text-align:center">10</th>
<th style="text-align:center">11</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">RI</td>
<td style="text-align:center">0</td>
<td style="text-align:center">0</td>
<td style="text-align:center">0.58</td>
<td style="text-align:center">0.90</td>
<td style="text-align:center">1.12</td>
<td style="text-align:center">1.24</td>
<td style="text-align:center">1.32</td>
<td style="text-align:center">1.41</td>
<td style="text-align:center">1.45</td>
<td style="text-align:center">1.49</td>
<td style="text-align:center">1.51</td>
</tr>
</tbody>
</table>
</div>
<p>然后再定义<strong>一致性比率$CR$</strong>：</p>
<script type="math/tex; mode=display">
CR=\frac {CI}{RI}</script><p>那么当$CR$小于0.1的时候，认为不一致阵A的不一致程度在允许范围内，有满意的一致性，通过了一致性检验，可以使用最大特征值对应的特征向量归一化之后的结果作为权向量。否则重新构造判断矩阵。</p>
<p>继续上面的旅游的例子，我们对其进行一致性检验。</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220105004755325.png" alt="层次单排序及其一致性检验的例子"></p>
<p>因此，旅游问题中对我们给出的判断矩阵可以得到从我们的观点出发，每个因素的得分向量为：</p>
<script type="math/tex; mode=display">
\vec w =[0.263, 0.475, 0.055, 0.090, 0.110]^T</script><p>因此，在我们看来，费用是我们在考虑目的地时候最重要的因素，接下来是景色，最后是旅途、饮食和居住</p>
<h3 id="D-层次总排序以及其一致性检验"><a href="#D-层次总排序以及其一致性检验" class="headerlink" title="D. 层次总排序以及其一致性检验"></a>D. 层次总排序以及其一致性检验</h3><h4 id="1-层次总排序"><a href="#1-层次总排序" class="headerlink" title="1) 层次总排序"></a>1) 层次总排序</h4><p>层次总排序指的是计算所有因素相对于总目标的相对重要性的权值的过程</p>
<p>这一过程从最高层到最底层依次进行。</p>
<p>例如前面的旅游目的地选取。</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220104233208220.png" alt="旅游目的地选择问题"></p>
<p>我们通过第三步已经有了准则层，即$C_1,C_2,C_3,C_4,C_5$之间的相对重要性。我们接下来是让方案层中的三个目的地对准则层中的每一个准侧进行比较。即在景色的角度来说，桂林比黄山、北戴河好到哪里去。此时又可以进行第二三步，即构造比较矩阵，进行层次单排序。</p>
<p>由于针对一个指标就可以获得一个层次单排序后的向量，例如对景色会得到一个景色单排序向量，因此最终会得到一个矩阵。</p>
<p>对于上面的旅游选择问题，最后得到的矩阵形状为$5\times3$，记该矩阵为$B$。接下来将准则层的得分向量左乘$B$矩阵，就得到了在方案层的层次总排序</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220105010617987.png" alt="层次总排序" style="zoom: 67%;"></p>
<h4 id="2-一致性检验-1"><a href="#2-一致性检验-1" class="headerlink" title="2) 一致性检验"></a>2) 一致性检验</h4><p>类似的，我们从几个不同的指标对每个方案的打分都是主观的，因此对于单个指标的对比矩阵，会出现不一致的情况。因此还要继续进行一致性检验。</p>
<p>我们对每一个指标$A_j$都可以计算其一致性指标$CI_j$、随机一致性指标$RI_j$，$j=1,2,\cdots,m$，则层次总排序的一致性比率为:</p>
<script type="math/tex; mode=display">
CR=\frac{a_1CI_1+a_2CI_2+\cdots+a_mCI_m}{a_1RI_1+a_2RI_2+\cdots+a_mRI_m}</script><p>同样，当$CR\leq 0.1$时候，则表示通过层次一致性检验，注意，这里的$A=[a_1,a_2,\cdots,a_n]$是经过归一化之后准则的权重向量值</p>
<p>我们继续上面的旅游的例子，那么有</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220105012126634.png" alt="层次总排序以及其一致性检验1"></p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220105012208466.png" alt="层次总排序以及其一致性检验2"></p>
<p>组合权向量即方案最终的得分。计算方法就是用准则层的每个准则得分和某个城市在这几个准则上的得分做内机，最后得到的分数</p>
<h2 id="4-层次分析法总结"><a href="#4-层次分析法总结" class="headerlink" title="4. 层次分析法总结"></a>4. 层次分析法总结</h2><p>最后，对层次分析法的流程做一个总结</p>
<ol>
<li>建立层次结构模型。该结构图包括目标层，准则层，方案层</li>
<li>构造成对比较矩阵。从第二层开始用成对比较矩阵和1-9尺度</li>
<li>计算单排序权向量并做一致性检验。对每个成对比较矩阵计算最大特征值及其对应的特征向量，利用一致性指标、随机一致性指标和一致性比率做一致性检验。 若检验通过，特征向量（归一化后）即为权向量；若不通过， 需要重新构造成对比较矩阵</li>
<li>计算总排序权向量并做一致性检验。计算最下层对最上层总排序的权向量，利用总排序一致性比率，进行检验。若通过，则可按照总排序权向量表示的结果进 行决策，否则需要重新考虑模型或重新构造那些一致性比率较大的成对比较矩阵</li>
</ol>
<h2 id="5-层次分析法Python求解"><a href="#5-层次分析法Python求解" class="headerlink" title="5. 层次分析法Python求解"></a>5. 层次分析法Python求解</h2><p>由于层次分析法全部都是矩阵乘法，因此Numpy和Pandas即可求解，下面的这个只是一个初级版本，实现了层次分析法，但是没有实现从表格中读取，也没有给出GUI的输入，后面等开始大美赛前再完善一下吧</p>
<pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">import</span> numpy <span class="token keyword">as</span> np
<span class="token keyword">import</span> pandas <span class="token keyword">as</span> pd
<span class="token keyword">from</span> typing <span class="token keyword">import</span> <span class="token operator">*</span>
<span class="token keyword">from</span> colorama <span class="token keyword">import</span> Fore<span class="token punctuation">,</span> Style


<span class="token keyword">class</span> <span class="token class-name">AnalyticHierarchyProcess</span><span class="token punctuation">(</span>object<span class="token punctuation">)</span><span class="token punctuation">:</span>
    RI <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0.58</span><span class="token punctuation">,</span> <span class="token number">0.9</span><span class="token punctuation">,</span> <span class="token number">1.12</span><span class="token punctuation">,</span> <span class="token number">1.32</span><span class="token punctuation">,</span> <span class="token number">1.41</span><span class="token punctuation">,</span> <span class="token number">1.45</span><span class="token punctuation">,</span> <span class="token number">1.49</span><span class="token punctuation">)</span>
    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> criteria<span class="token punctuation">:</span> Union<span class="token punctuation">[</span>List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> int<span class="token punctuation">]</span><span class="token punctuation">,</span> plans<span class="token punctuation">:</span> Union<span class="token punctuation">[</span>List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> int<span class="token punctuation">]</span><span class="token punctuation">,</span> method<span class="token operator">=</span><span class="token string">"manual"</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> None<span class="token punctuation">:</span>
        super<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>__init__<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">assert</span> method <span class="token keyword">in</span> <span class="token punctuation">[</span><span class="token string">"csv"</span><span class="token punctuation">,</span> <span class="token string">"manual"</span><span class="token punctuation">]</span>
        self<span class="token punctuation">.</span>criteria_name <span class="token operator">=</span> <span class="token punctuation">[</span>f<span class="token string">"准则{i}"</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span>criteria<span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token keyword">if</span> isinstance<span class="token punctuation">(</span>criteria<span class="token punctuation">,</span> int<span class="token punctuation">)</span> <span class="token keyword">else</span> criteria
        self<span class="token punctuation">.</span>criteria <span class="token operator">=</span> self<span class="token punctuation">.</span>get_criteria<span class="token punctuation">(</span>criteria_names<span class="token operator">=</span>self<span class="token punctuation">.</span>criteria_name<span class="token punctuation">,</span> method<span class="token operator">=</span>method<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>plan_names <span class="token operator">=</span> <span class="token punctuation">[</span>f<span class="token string">"方案{i}"</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span>plans<span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token keyword">if</span> isinstance<span class="token punctuation">(</span>plans<span class="token punctuation">,</span> int<span class="token punctuation">)</span> <span class="token keyword">else</span> plans
        self<span class="token punctuation">.</span>plan_scores <span class="token operator">=</span> self<span class="token punctuation">.</span>get_plan_scores<span class="token punctuation">(</span>self<span class="token punctuation">.</span>plan_names<span class="token punctuation">,</span> self<span class="token punctuation">.</span>criteria_name<span class="token punctuation">,</span> method<span class="token operator">=</span>method<span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">matrix2str</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> column<span class="token punctuation">:</span> List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> index<span class="token punctuation">:</span> List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> str<span class="token punctuation">:</span>
        ss <span class="token operator">=</span> pd<span class="token punctuation">.</span>DataFrame<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria<span class="token punctuation">,</span> index<span class="token operator">=</span>index<span class="token punctuation">,</span> columns<span class="token operator">=</span>column<span class="token punctuation">)</span>
        <span class="token keyword">return</span> ss<span class="token punctuation">.</span>__str__<span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">run</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"开始层次单排序"</span><span class="token punctuation">)</span>
        eigvalue<span class="token punctuation">,</span> eigvector <span class="token operator">=</span> np<span class="token punctuation">.</span>linalg<span class="token punctuation">.</span>eig<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria<span class="token punctuation">)</span>
        <span class="token keyword">if</span> len<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"标准对比矩阵为一致阵"</span><span class="token punctuation">)</span>
            w <span class="token operator">=</span> eigvector
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"标准对比矩阵为非一致阵，开始进行一致性检验"</span><span class="token punctuation">)</span>
            ci <span class="token operator">=</span> <span class="token punctuation">(</span>max<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span> <span class="token operator">-</span> len<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token punctuation">(</span>len<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>cr <span class="token punctuation">:</span><span class="token operator">=</span> ci<span class="token operator">/</span>self<span class="token punctuation">.</span>RI<span class="token punctuation">[</span>len<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">&lt;</span> <span class="token number">0.1</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"层次单排序一致性检验一致性比率CR={cr:>.3f}，通过检验"</span><span class="token punctuation">)</span>
                w <span class="token operator">=</span> eigvector<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">,</span> np<span class="token punctuation">.</span>argmax<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span><span class="token punctuation">]</span>
            <span class="token keyword">else</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>matrix2str<span class="token punctuation">(</span>column<span class="token operator">=</span>self<span class="token punctuation">.</span>criteria_name<span class="token punctuation">,</span> index<span class="token operator">=</span>self<span class="token punctuation">.</span>criteria_name<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token keyword">assert</span> <span class="token boolean">False</span><span class="token punctuation">,</span> f<span class="token string">"层次单排序一致性检验未通过， CR={cr:>.3f}"</span>
        <span class="token comment" spellcheck="true"># 归一化处理，softmax</span>
        w <span class="token operator">=</span> w <span class="token operator">/</span> sum<span class="token punctuation">(</span>w<span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"开始层次总排序"</span><span class="token punctuation">)</span>
        m <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        ci_all <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        ri_all <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token keyword">for</span> c_name<span class="token punctuation">,</span> c_score <span class="token keyword">in</span> zip<span class="token punctuation">(</span>self<span class="token punctuation">.</span>criteria_name<span class="token punctuation">,</span> self<span class="token punctuation">.</span>plan_scores<span class="token punctuation">)</span><span class="token punctuation">:</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"针对 {Fore.GREEN}{c_name}{Style.RESET_ALL} 进行层次单排序"</span><span class="token punctuation">)</span>
            eigvalue<span class="token punctuation">,</span> eigvector <span class="token operator">=</span> np<span class="token punctuation">.</span>linalg<span class="token punctuation">.</span>eig<span class="token punctuation">(</span>c_score<span class="token punctuation">)</span>
            <span class="token keyword">if</span> len<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"{Fore.GREEN}{c_name}{Style.RESET_ALL} 的对比矩阵为一致阵"</span><span class="token punctuation">)</span>
                m<span class="token punctuation">.</span>append<span class="token punctuation">(</span>eigvector <span class="token operator">/</span> sum<span class="token punctuation">(</span>eigvector<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">else</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"{Fore.GREEN}{c_name}{Style.RESET_ALL} 的对比矩阵为非一致阵"</span><span class="token punctuation">)</span>
                ci <span class="token operator">=</span> <span class="token punctuation">(</span>max<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span> <span class="token operator">-</span> len<span class="token punctuation">(</span>c_score<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token punctuation">(</span>len<span class="token punctuation">(</span>c_score<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>cr <span class="token punctuation">:</span><span class="token operator">=</span> ci<span class="token operator">/</span>self<span class="token punctuation">.</span>RI<span class="token punctuation">[</span>len<span class="token punctuation">(</span>c_score<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">&lt;</span> <span class="token number">0.1</span><span class="token punctuation">:</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"{Fore.YELLOW}{c_name}{Style.RESET_ALL}层次单排序一致性检验一致性比率CR={cr:>.3f}，通过检验"</span><span class="token punctuation">)</span>
                    e <span class="token operator">=</span> eigvector<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">,</span> np<span class="token punctuation">.</span>argmax<span class="token punctuation">(</span>eigvalue<span class="token punctuation">)</span><span class="token punctuation">]</span>
                    m<span class="token punctuation">.</span>append<span class="token punctuation">(</span>e <span class="token operator">/</span> sum<span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token keyword">else</span><span class="token punctuation">:</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>matrix2str<span class="token punctuation">(</span>self<span class="token punctuation">.</span>plan_names<span class="token punctuation">,</span> self<span class="token punctuation">.</span>plan_names<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    <span class="token keyword">assert</span> <span class="token boolean">False</span><span class="token punctuation">,</span> f<span class="token string">"{Fore.YELLOW}{c_name}{Style.RESET_ALL}层次单排序一致性检验未通过， CR={cr:>.3f}"</span>
            ci_all<span class="token punctuation">.</span>append<span class="token punctuation">(</span>ci<span class="token punctuation">)</span>
            ri_all<span class="token punctuation">.</span>append<span class="token punctuation">(</span>self<span class="token punctuation">.</span>RI<span class="token punctuation">[</span>len<span class="token punctuation">(</span>c_score<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
        <span class="token keyword">assert</span> <span class="token punctuation">(</span>cr<span class="token punctuation">:</span><span class="token operator">=</span><span class="token punctuation">(</span>np<span class="token punctuation">.</span>array<span class="token punctuation">(</span>ci_all<span class="token punctuation">)</span> @ w<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token punctuation">(</span>np<span class="token punctuation">.</span>array<span class="token punctuation">(</span>ri_all<span class="token punctuation">)</span> @ w<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">&lt;</span> <span class="token number">0.1</span><span class="token punctuation">,</span> f<span class="token string">"层次总排序一致性检验未通过，CR={cr:>.3f}"</span>
        m <span class="token operator">=</span> np<span class="token punctuation">.</span>array<span class="token punctuation">(</span>m<span class="token punctuation">)</span>
        final_score <span class="token operator">=</span> w @ m
        <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"最终得分:{final_score}"</span><span class="token punctuation">)</span>




    @staticmethod
    <span class="token keyword">def</span> <span class="token function">get_criteria</span><span class="token punctuation">(</span>criteria_names<span class="token punctuation">:</span> List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> method<span class="token punctuation">:</span> str<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> np<span class="token punctuation">.</span>ndarray<span class="token punctuation">:</span>
        <span class="token keyword">if</span> method <span class="token operator">==</span> <span class="token string">"manual"</span><span class="token punctuation">:</span>
            criteria <span class="token operator">=</span> np<span class="token punctuation">.</span>eye<span class="token punctuation">(</span>N<span class="token operator">=</span><span class="token punctuation">(</span>l<span class="token punctuation">:</span><span class="token operator">=</span>len<span class="token punctuation">(</span>criteria_names<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"="</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"请输入评价标准之间的相对重要性（1-9，1，3，5，7，9分别表示标准A比标准B：同等重要、稍微重要、比较重要、很重要、绝对重要，2，4，6，8分别为中位数）"</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"若标准A不如标准B重要，则输入1/标准B比标准A的相对重要性，例如标准A不如标准B重要，而标准B比标准A为3，那么标准A比标准B为1/3"</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"+"</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span>l<span class="token punctuation">)</span><span class="token punctuation">:</span>
                <span class="token keyword">for</span> j <span class="token keyword">in</span> range<span class="token punctuation">(</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span>  l<span class="token punctuation">)</span><span class="token punctuation">:</span>
                    <span class="token keyword">if</span> <span class="token string">"/"</span> <span class="token operator">not</span> <span class="token keyword">in</span> <span class="token punctuation">(</span>inp<span class="token punctuation">:</span><span class="token operator">=</span>input<span class="token punctuation">(</span>f<span class="token string">"请输入 {Fore.GREEN}{criteria_names[i]}{Style.RESET_ALL} 对 {Fore.GREEN}{criteria_names[j]}{Style.RESET_ALL} 的相对重要性："</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                        criteria<span class="token punctuation">[</span>i<span class="token punctuation">,</span> j<span class="token punctuation">]</span> <span class="token operator">=</span> int<span class="token punctuation">(</span>inp<span class="token punctuation">)</span>
                    <span class="token keyword">else</span><span class="token punctuation">:</span>
                        upper<span class="token punctuation">,</span> lower <span class="token operator">=</span> <span class="token punctuation">[</span>int<span class="token punctuation">(</span>j<span class="token punctuation">)</span> <span class="token keyword">for</span> j <span class="token keyword">in</span> inp<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">"/"</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
                        criteria<span class="token punctuation">[</span>i<span class="token punctuation">,</span> j<span class="token punctuation">]</span> <span class="token operator">=</span> upper <span class="token operator">/</span> lower
                <span class="token keyword">if</span> i<span class="token operator">+</span><span class="token number">1</span> <span class="token operator">&lt;</span> l<span class="token punctuation">:</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"+"</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
            position <span class="token operator">=</span> np<span class="token punctuation">.</span>where<span class="token punctuation">(</span>criteria<span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span>
            criteria<span class="token punctuation">[</span>position<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">/</span> criteria<span class="token punctuation">.</span>transpose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span>position<span class="token punctuation">]</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"输入的评价标准之间的对比矩阵为："</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span>criteria<span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"="</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
        <span class="token keyword">elif</span> method <span class="token operator">==</span> <span class="token string">"csv"</span><span class="token punctuation">:</span>
            <span class="token keyword">pass</span>
        <span class="token keyword">return</span> criteria

    @staticmethod
    <span class="token keyword">def</span> <span class="token function">get_plan_scores</span><span class="token punctuation">(</span>plan_names<span class="token punctuation">:</span> List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> criteria_names<span class="token punctuation">:</span> List<span class="token punctuation">[</span>str<span class="token punctuation">]</span><span class="token punctuation">,</span> method<span class="token punctuation">:</span> str<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> np<span class="token punctuation">.</span>ndarray<span class="token punctuation">:</span>
        <span class="token keyword">if</span> method <span class="token operator">==</span> <span class="token string">"manual"</span><span class="token punctuation">:</span>
            plan_scores <span class="token operator">=</span> np<span class="token punctuation">.</span>repeat<span class="token punctuation">(</span>np<span class="token punctuation">.</span>eye<span class="token punctuation">(</span>N<span class="token operator">=</span>len<span class="token punctuation">(</span>plan_names<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span>reshape<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> len<span class="token punctuation">(</span>plan_names<span class="token punctuation">)</span><span class="token punctuation">,</span> len<span class="token punctuation">(</span>plan_names<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> repeats<span class="token operator">=</span>len<span class="token punctuation">(</span>criteria_names<span class="token punctuation">)</span><span class="token punctuation">,</span> axis<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"="</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"请输入不同方案之间就某一个标准的的相对重要性（1-9，1，3，5，7，9分别表示标准A比标准B：同等重要、稍微重要、比较重要、很重要、绝对重要，2，4，6，8分别为中位数）"</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"若就标准X，方案A不如方案B重要，则输入1/方案B比方案A的相对重要性，例如就标准X，方案A不如方案B重要，而方案B比方案A为3，那么方案A比方案B为1/3"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> i <span class="token keyword">in</span> range<span class="token punctuation">(</span>len<span class="token punctuation">(</span>criteria_names<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>f<span class="token string">"就 {Fore.YELLOW}{criteria_names[i]}{Style.RESET_ALL} 对方案之间的得分进行比较"</span><span class="token punctuation">.</span>center<span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token string">"+"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token keyword">for</span> j <span class="token keyword">in</span> range<span class="token punctuation">(</span>l <span class="token punctuation">:</span><span class="token operator">=</span> len<span class="token punctuation">(</span>plan_names<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                    <span class="token keyword">for</span> k <span class="token keyword">in</span> range<span class="token punctuation">(</span>j<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span> l<span class="token punctuation">)</span><span class="token punctuation">:</span>
                        <span class="token keyword">if</span> <span class="token string">"/"</span> <span class="token operator">not</span> <span class="token keyword">in</span> <span class="token punctuation">(</span>inp<span class="token punctuation">:</span><span class="token operator">=</span>input<span class="token punctuation">(</span>f<span class="token string">"请从 {Fore.YELLOW}{criteria_names[i]}{Style.RESET_ALL} 的角度，输入 {Fore.GREEN}{plan_names[j]}{Style.RESET_ALL} 对 {Fore.GREEN}{plan_names[k]}{Style.RESET_ALL} 的相对重要性："</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                            plan_scores<span class="token punctuation">[</span>i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> k<span class="token punctuation">]</span> <span class="token operator">=</span> int<span class="token punctuation">(</span>inp<span class="token punctuation">)</span>
                        <span class="token keyword">else</span><span class="token punctuation">:</span>
                            upper<span class="token punctuation">,</span> lower <span class="token operator">=</span> <span class="token punctuation">[</span>int<span class="token punctuation">(</span>j<span class="token punctuation">)</span> <span class="token keyword">for</span> j <span class="token keyword">in</span> inp<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">"/"</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
                            plan_scores<span class="token punctuation">[</span>i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> k<span class="token punctuation">]</span> <span class="token operator">=</span> upper <span class="token operator">/</span> lower
                position <span class="token operator">=</span> np<span class="token punctuation">.</span>where<span class="token punctuation">(</span>plan_scores<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
                plan_scores<span class="token punctuation">[</span>i<span class="token punctuation">,</span> position<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> position<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">/</span> plan_scores<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>transpose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span>position<span class="token punctuation">]</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"输入的不同评价标准下方案间的对比矩阵为："</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> c<span class="token punctuation">,</span> s <span class="token keyword">in</span> zip<span class="token punctuation">(</span>criteria_names<span class="token punctuation">,</span> plan_scores<span class="token punctuation">)</span><span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"="</span><span class="token operator">*</span><span class="token number">200</span><span class="token punctuation">)</span>
        <span class="token keyword">elif</span> method <span class="token operator">==</span> <span class="token string">"csv"</span><span class="token punctuation">:</span>
            <span class="token keyword">pass</span>
        <span class="token keyword">return</span> plan_scores




<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">"__main__"</span><span class="token punctuation">:</span>
    ahp <span class="token operator">=</span> AnalyticHierarchyProcess<span class="token punctuation">(</span>criteria<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">"景色"</span><span class="token punctuation">,</span> <span class="token string">"费用"</span><span class="token punctuation">,</span> <span class="token string">"居住"</span><span class="token punctuation">,</span> <span class="token string">"饮食"</span><span class="token punctuation">,</span> <span class="token string">"旅途"</span><span class="token punctuation">]</span><span class="token punctuation">,</span> plans<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">"苏杭"</span><span class="token punctuation">,</span> <span class="token string">"北戴河"</span><span class="token punctuation">,</span> <span class="token string">"桂林"</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    ahp<span class="token punctuation">.</span>run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>运行结果</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220106135400089.png" alt="层次分析法运行结果"></p>
<h2 id="6-层次分析法例题"><a href="#6-层次分析法例题" class="headerlink" title="6. 层次分析法例题"></a>6. 层次分析法例题</h2><h3 id="A-队员选拔问题"><a href="#A-队员选拔问题" class="headerlink" title="A. 队员选拔问题"></a>A. 队员选拔问题</h3><h4 id="A-问题"><a href="#A-问题" class="headerlink" title="A. 问题"></a>A. 问题</h4><blockquote>
<p>设某学校数学建模教练组根据实际需要，拟从报名参赛的20名队员中选出15名优秀队员代表学校参赛。 表1给出了20名队员的基本条件的量化情况。 请根据这些条件对20名队员进行综合评价，从中选出15名综合素质较高的优秀队员</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220106140221242.png" alt="队员基本情况表" style="zoom: 50%;"></p>
</blockquote>
<h4 id="B-问题分析"><a href="#B-问题分析" class="headerlink" title="B. 问题分析"></a>B. 问题分析</h4><p>这是一个半定性与半定量、多因素的综合选优排序问题． 鉴于数学建模竞赛不仅要考查学生的学科知识、还要考查学生的 作能力、计算机应用能力、团结协助能力等多方面的因素，要 从20名队员中选拔出优秀参赛队员，就要对表1中所列的六个因素进行比较分析，综合排序选优，从而选取前几名学生。</p>
<h4 id="C-假设"><a href="#C-假设" class="headerlink" title="C. 假设"></a>C. 假设</h4><ol>
<li>题目中所确定的考评条件是合理的，能够反映出参选队员的建模能力</li>
<li>各参选队员的量化得分是按统一的量化标准得出的</li>
<li>对参选队员的量化打分是公平的，所有参选队员对打分结果无异议</li>
<li>选拔队员所考虑的六个因素在选拔优秀队员中所起的作用依次为学科知识竞赛成绩、思维敏捷度、知识面宽广度、写作能力、计算机应用能力、团结协助能力，并且相邻两个因素的影响程度之差基本相同</li>
</ol>
<h4 id="D-模型建立"><a href="#D-模型建立" class="headerlink" title="D. 模型建立"></a>D. 模型建立</h4><p>根绝题目要求和分析与假设，建立如下的层次结构图</p>
<ol>
<li><strong>第一层为目标层</strong>：选拔优秀参赛队员</li>
<li><strong>第二层为准则层</strong>：选拔优秀队员时所考虑的6个因素，依次为学科知识竞赛成绩、思维敏捷度、知识面宽广度、写作能力、计 算机应用能力、协助能力</li>
<li><strong>第三层为方案层</strong>：参选的20名队员</li>
</ol>
<p>结构图如下：</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220106143423911.png" alt="队员选拔问题层次结构图"></p>
<h4 id="E-模型求解"><a href="#E-模型求解" class="headerlink" title="E. 模型求解"></a>E. 模型求解</h4><ol>
<li><p><strong>确定准则层对目标层的权重向量</strong>：根据假设，构造准则层$C$的准则间的比较矩阵</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220106143632490.png" alt="准则层C的比较矩阵" style="zoom:50%;"></p>
</li>
<li><p><strong>确定方案层对准则层的权重向量</strong>：根据表1和模型假设，构造方案层$P$中20个队员对准则层$C$中各因素$C_k$的两两比较矩阵。构造方式为分数的两两比较</p>
</li>
<li><p><strong>求解</strong>：结果如下</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/image-20220106144434996.png" alt="求解结果"></p>
</li>
</ol>
<h4 id="F-模型分析"><a href="#F-模型分析" class="headerlink" title="F. 模型分析"></a>F. 模型分析</h4><ul>
<li>由表1，20名队员六项条件互有强弱，利用层次分析法 得到了一种合理的综合排序方案，结果选出了综合实力较强的 15名队员</li>
<li>第13号队员各项条件总体较强，排在了第一位</li>
<li>第9号和第10号队员各项条件总体较弱，排在后两位</li>
</ul>
<h2 id="7-层次分析法的综合评价"><a href="#7-层次分析法的综合评价" class="headerlink" title="7. 层次分析法的综合评价"></a>7. 层次分析法的综合评价</h2><p>最后，给出层次分析法的整体上的一个评价</p>
<p>首先是优点：</p>
<ul>
<li><strong>系统性</strong>：把所研究的问题看成一个系统，按照分解、比较判断、 综合分析的思维方式进行决策分析，也是实际中继机理分析方法、统 计分析方法之后发展起来的又一个重要的系统分析工具．</li>
<li><strong>实用性</strong>：把定性与定量方法结合起来，能处理许多传统的优化 方法无法处理的实际问题，应用范围广．而且将决策者和决策分析者 联系起来，体现了决策者的主观意见，决策者可以直接应用它进行决 策分析，增加了决策的有效性和实用性．</li>
<li><strong>简洁性</strong>：具有中等文化程度的人都可以学习掌握层次分析法的基 本原理和步骤，计算也比较简便，所得结果简单明确，容易被决策者 了解和掌握．</li>
</ul>
<p>然后是其缺点：</p>
<ul>
<li>局限性是粗略、主观．首先是它的比较、判断及结果都是粗糙的， 不适于精度要求很高的问题</li>
<li>其次是从建立层次结构图到给出两两比较矩阵，人的主观因素作用 很大，使决策结果较大程度地依赖于决策人的主观意志，可能难以为 众人所接受</li>
</ul>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">Jack Wang</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://jackwang0107.github.io/2022/01/04/shu-xue-jian-mo-suan-fa-5-ceng-ci-fen-xi-fa/">https://jackwang0107.github.io/2022/01/04/shu-xue-jian-mo-suan-fa-5-ceng-ci-fen-xi-fa/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">Jack Wang</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Python/">
                                    <span class="chip bg-color">Python</span>
                                </a>
                            
                                <a href="/tags/Math-Modeling/">
                                    <span class="chip bg-color">Math Modeling</span>
                                </a>
                            
                                <a href="/tags/%E5%B1%82%E6%AC%A1%E5%88%86%E6%9E%90%E6%B3%95/">
                                    <span class="chip bg-color">层次分析法</span>
                                </a>
                            
                                <a href="/tags/Analytic-Hierarchy-Process/">
                                    <span class="chip bg-color">Analytic Hierarchy Process</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2022/01/06/shu-xue-jian-mo-suan-fa-6-hui-se-guan-lian-fen-xi-yu-yu-ce/">
                    <div class="card-image">
                        
                        <img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/Steps-for-inscribed-cored-grey-relational-analysis-model-IC-GRA-model-calculations.png" class="responsive-img" alt="数学建模算法6-灰色关联分析与预测">
                        
                        <span class="card-title">数学建模算法6-灰色关联分析与预测</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本文主要介绍了数学建模中常见的分析与预测算法：灰色关联分析和灰色预测
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-01-06
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AE%97%E6%B3%95/" class="post-category">
                                    数学建模算法
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Python/">
                        <span class="chip bg-color">Python</span>
                    </a>
                    
                    <a href="/tags/Math-Modeling/">
                        <span class="chip bg-color">Math Modeling</span>
                    </a>
                    
                    <a href="/tags/%E7%81%B0%E8%89%B2%E5%85%B3%E8%81%94%E5%88%86%E6%9E%90/">
                        <span class="chip bg-color">灰色关联分析</span>
                    </a>
                    
                    <a href="/tags/%E7%81%B0%E8%89%B2%E9%A2%84%E6%B5%8B/">
                        <span class="chip bg-color">灰色预测</span>
                    </a>
                    
                    <a href="/tags/%E7%81%B0%E8%89%B2%E6%A8%A1%E5%9E%8B/">
                        <span class="chip bg-color">灰色模型</span>
                    </a>
                    
                    <a href="/tags/Grey-relational-analysis/">
                        <span class="chip bg-color">Grey relational analysis</span>
                    </a>
                    
                    <a href="/tags/Grey-Model/">
                        <span class="chip bg-color">Grey Model</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2022/01/04/shu-xue-jian-mo-suan-fa-4-fei-xian-xing-gui-hua/">
                    <div class="card-image">
                        
                        <img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/img/v2-69cfe96a3fb52b79353c03cadb085a3b_1440w.jpg" class="responsive-img" alt="数学建模算法4-非线性规划">
                        
                        <span class="card-title">数学建模算法4-非线性规划</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本文主要讲解了数学建模中常见的一类问题：非线性规划，及其求解
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-01-04
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AE%97%E6%B3%95/" class="post-category">
                                    数学建模算法
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Python/">
                        <span class="chip bg-color">Python</span>
                    </a>
                    
                    <a href="/tags/Math-Modeling/">
                        <span class="chip bg-color">Math Modeling</span>
                    </a>
                    
                    <a href="/tags/%E9%9D%9E%E7%BA%BF%E6%80%A7%E8%A7%84%E5%88%92/">
                        <span class="chip bg-color">非线性规划</span>
                    </a>
                    
                    <a href="/tags/Non-Linear-Programming/">
                        <span class="chip bg-color">Non-Linear Programming</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: JackWang&#39;s Blog<br />'
            + '文章作者: Jack Wang<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('2'),
            headingSelector: 'h1, h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>


<script src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
    MathJax.Hub.Config({
        tex2jax: {inlineMath: [['$', '$'], ['\\(', '\\)']]}
    });
</script>



    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2021-2023</span>
            
            <a href="/about" target="_blank">Jack Wang</a>
            <!-- |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a> -->
            <!-- |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a> -->
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">603.8k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
                <span id="sitetime"> Loading ...</span>
                <script>
                    var calcSiteTime = function () {
                        var seconds = 1000;
                        var minutes = seconds * 60;
                        var hours = minutes * 60;
                        var days = hours * 24;
                        var years = days * 365;
                        var today = new Date();
                        var startYear = "2021";
                        var startMonth = "11";
                        var startDate = "12";
                        var startHour = "0";
                        var startMinute = "0";
                        var startSecond = "0";
                        var todayYear = today.getFullYear();
                        var todayMonth = today.getMonth() + 1;
                        var todayDate = today.getDate();
                        var todayHour = today.getHours();
                        var todayMinute = today.getMinutes();
                        var todaySecond = today.getSeconds();
                        var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                        var diff = t2 - t1;
                        var diffYears = Math.floor(diff / years);
                        var diffDays = Math.floor((diff / days) - diffYears * 365);

                        // 区分是否有年份.
                        var language = 'zh-CN';
                        if (startYear === String(todayYear)) {
                            document.getElementById("year").innerHTML = todayYear;
                            var daysTip = 'This site has been running for ' + diffDays + ' days';
                            if (language === 'zh-CN') {
                                daysTip = '本站已运行 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                daysTip = '本站已運行 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = daysTip;
                        } else {
                            document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                            var yearsAndDaysTip = 'This site has been running for ' + diffYears + ' years and '
                                + diffDays + ' days';
                            if (language === 'zh-CN') {
                                yearsAndDaysTip = '本站已运行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                yearsAndDaysTip = '本站已運行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = yearsAndDaysTip;
                        }
                    }

                    calcSiteTime();
                </script>
            
            <br>
            
                <span id="icp"><img src="/medias/icp.png"
                                    style="vertical-align: text-bottom;"/>
                <a href="https://beian.miit.gov.cn" target="_blank">陕ICP备2021014294号-1</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/jackwang0108" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:2232123545@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2232123545" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2232123545" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    

    
        
        <script type="text/javascript">
            // 只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/libs/others/sakura.js"><\/script>');
            }
        </script>
    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
